package com.aku.controller.page;


import com.aku.pojo.Book;
import com.aku.pojo.User;
import com.aku.service.BookService;
import com.aku.service.BorrowService;
import com.aku.service.StudentService;
import com.aku.vo.ShowBorrow;
import com.aku.vo.ShowStudent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/page/admin")
public class PageAdminController {

    @Resource
    private BookService bookService;
    @Resource
    private BorrowService borrowService;
    @Resource
    private StudentService studentService;

    @RequestMapping("/adminBookInfo")
    public String adminBookInfo  (
            @SessionAttribute("user") User user, Model model){
        List<Book> books  = bookService.findAllBook();
        model.addAttribute("user",user);
        model.addAttribute("books",books);
        return "/admin/admin_bookInfo";
    }

    @RequestMapping("/adminBorrowInfo")
    public String adminBorrowInfo  (
            @SessionAttribute("user") User user, Model model){
        model.addAttribute("user",user);
        List<ShowBorrow> borrowList = borrowService.selectAllBorrow();
        model.addAttribute("borrowList",borrowList);
        return "/admin/admin_borrowInfo";
    }

    @RequestMapping("/adminStuInfo")
    public String adminStuInfo (
            @SessionAttribute("user") User user, Model model){
        model.addAttribute("user",user);
        List<ShowStudent> showStudentList = studentService.searchStudentsBorrow();
        model.addAttribute("studentList",showStudentList);
        return "/admin/admin_stuInfo";
    }

    @RequestMapping("/adminAddBook")
    public String adminAddBook (
            @SessionAttribute("user") User user, Model model){
        model.addAttribute("user",user);
        return "/admin/admin_addBook";
    }
    @RequestMapping("/adminAddStu")
    public String adminAddStu (
            @SessionAttribute("user") User user, Model model){
        model.addAttribute("user",user);
        return "/admin/admin_addStudent";
    }

}